//
//  Tab3ViewController.m
//  SITABLE
//
//  Created by songjun on 16/9/18.
//  Copyright © 2016年 Sita. All rights reserved.
//

#import "Tab3ViewController.h"
#define HearviewH 140
#define RowsNumber 2
#define RowH 50
@interface Tab3ViewController ()

@end

@implementation Tab3ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    infoArr = [NSMutableArray arrayWithCapacity:1];
    [infoArr addObject:@"我的车辆"];
     //[infoArr addObject:@"个人资料"];
     [infoArr addObject:@"关于"];
    
    //carLocation
    
    imageNameArr =[NSMutableArray arrayWithCapacity:1];
    [imageNameArr addObject:@"startPoint"];
    //[imageNameArr addObject:@"startPoint"];
    [imageNameArr addObject:@"startPoint"];

    
      self.title = NSLocalizedStringFromTable(@"Mine", @"InfoPlist", nil);
    baseTableview.backgroundColor = [UIColor whiteColor];
    
    
    if ([baseTableview respondsToSelector:@selector(setSeparatorInset:)]) {
        [baseTableview setSeparatorInset:UIEdgeInsetsZero];
    }
    
    if ([baseTableview respondsToSelector:@selector(setLayoutMargins:)]) {
        [baseTableview setLayoutMargins:UIEdgeInsetsZero];
    }
    [baseTableview setSeparatorColor:[UIColor clearColor]];
    self.view.backgroundColor = UIColorHexRGBA(linBoardBGGrayColor, 1.0);
    baseTableview.backgroundColor = UIColorHexRGBA(linBoardBGGrayColor, 1.0);
    
    baseTableview.tableFooterView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 0)];
    // Do any additional setup after loading the view.
    
    

}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    if (indexPath.section == 0) {
        //[[NSNotificationCenter defaultCenter] postNotificationName:@"logOff" object:nil];
        if (indexPath.row == 0) {
            MyCarsViewController *bikeDetect =  [[UIStoryboard storyboardWithName:@"Tab3" bundle:nil] instantiateViewControllerWithIdentifier:@"myCarsVc"];
            self.hidesBottomBarWhenPushed = YES;
            UIBarButtonItem *temporaryBarButtonItem = [[UIBarButtonItem alloc] init];
            temporaryBarButtonItem.title = @"";
            self.navigationItem.backBarButtonItem = temporaryBarButtonItem;
            [self.navigationController pushViewController:bikeDetect animated:YES];
            self.hidesBottomBarWhenPushed = NO;
            
        }
        
        if (indexPath.row ==1) {
            AboutUsViewController *bikeDetect =  [[UIStoryboard storyboardWithName:@"Tab3" bundle:nil] instantiateViewControllerWithIdentifier:@"aboutUsVc"];
            self.hidesBottomBarWhenPushed = YES;
            UIBarButtonItem *temporaryBarButtonItem = [[UIBarButtonItem alloc] init];
            temporaryBarButtonItem.title = @"";
            self.navigationItem.backBarButtonItem = temporaryBarButtonItem;
            [self.navigationController pushViewController:bikeDetect animated:YES];
            self.hidesBottomBarWhenPushed = NO;
        }

    }
    if (indexPath.section == 1) {
        [[NSNotificationCenter defaultCenter] postNotificationName:@"logOff" object:nil];
    }
    
}

-(void)tableView:(UITableView *)tableView willDisplayCell:(nonnull UITableViewCell *)cell forRowAtIndexPath:(nonnull NSIndexPath *)indexPath
{
        // 某一行分割线左对齐
        if ([cell respondsToSelector:@selector(setSeparatorInset:)]) {
            [cell setSeparatorInset:UIEdgeInsetsZero];
        }
        
        if ([cell respondsToSelector:@selector(setLayoutMargins:)]) {
            [cell setLayoutMargins:UIEdgeInsetsZero];
        }
}



- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    if (section == 0) {
        return HearviewH;
    }else{
        return 10;
    }
    return HearviewH;
}

- (nullable UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    
    if (section == 0) {
        UIView *headerview= [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, HearviewH)];
        UIImageView *userAvatarIv = [[UIImageView alloc] initWithFrame:CGRectMake(SCREEN_WIDTH/2-HearviewH/4, HearviewH/2-HearviewH/4, HearviewH/2, HearviewH/2)];
        userAvatarIv.image = [UIImage imageNamed:@"avatarIv"];
        userAvatarIv.userInteractionEnabled = YES;
        
        UITapGestureRecognizer *tapToMyselfInfo = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapToMyselfInfoAction)];
        
        [userAvatarIv addGestureRecognizer:tapToMyselfInfo];
        
        
        userAvatarIv.layer.cornerRadius =HearviewH/4;
        userAvatarIv.clipsToBounds = YES;
        [headerview addSubview:userAvatarIv];
        CGFloat nickY = CGRectGetMaxY(userAvatarIv.frame);
        
        UILabel *nickNameLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, nickY, SCREEN_WIDTH, 30)];
        nickNameLabel.tag = 1009;
        nickNameLabel.text = @"愤怒的番茄";
        nickNameLabel.font = linBoardFont15;
        nickNameLabel.textColor = [UIColor blackColor];
        [headerview addSubview:nickNameLabel];
        nickNameLabel.textAlignment = NSTextAlignmentCenter;
        
        headerview.backgroundColor = [UIColor whiteColor];
        return headerview;

    }else{
        UIView *testView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 10)];
        testView.backgroundColor = UIColorHexRGBA(linBoardBGGrayColor, 1.0);
        return testView;
    }
}

-(void)tapToMyselfInfoAction
{
    NSLog(@"dddddd");
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 2;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if (section == 0) {
        return RowsNumber;
    }
    
    if (section == 1) {
        return 1;
    }
    return RowsNumber;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *identify = @"cell";
    MyselfTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identify];
    if (cell == nil) {
        cell = [[[NSBundle mainBundle] loadNibNamed:@"MyselfTableViewCell" owner:self options:nil] lastObject];
        
    }
    if (indexPath.section == 0) {
        cell.inforlabel.text = [infoArr objectAtIndex:indexPath.row];
    if (indexPath.row == 1) {
        UILabel *lineLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 0, SCREEN_WIDTH, 0.5)];
        lineLabel.backgroundColor = UIColorHexRGBA(linBoardSepLineColor, 1.0);
        [cell.contentView addSubview:lineLabel];
    }
        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        
    }else{
        cell.inforlabel.text = @"";
        UILabel *quiteLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, RowH)];
        quiteLabel.textAlignment = NSTextAlignmentCenter;
        quiteLabel.text = @"退  出";
        quiteLabel.font = linBoardFont15;
        [cell.contentView  addSubview:quiteLabel];
           cell.selectionStyle = UITableViewCellSelectionStyleNone;
    }
    
   
   // cell.leftImv.image = [UIImage imageNamed:[imageNameArr objectAtIndex:indexPath.row]];
    

    
    
    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return RowH;
}

//- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
//{
//    return RowH;
//}

//- (nullable UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
//{
//
//    UIButton *quiteBtn = [UIButton buttonWithType:UIButtonTypeCustom];
//    quiteBtn.frame = CGRectMake(0, 0, SCREEN_WIDTH, RowH);
//    [quiteBtn setTitle:@"退    出" forState:UIControlStateNormal];
//    [quiteBtn addTarget:self action:@selector(quiteBtnAciton:) forControlEvents:UIControlEventTouchUpInside];
//    [quiteBtn setBackgroundColor:[UIColor whiteColor]];
//    [quiteBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
//    
//    UILabel *topLineLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 0.5)];
//    topLineLabel.backgroundColor = UIColorHexRGBA(linBoardSepLineColor, 1.0);
//    [quiteBtn addSubview:topLineLabel];
//    
//    UILabel *botomLineLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, RowH-0.5, SCREEN_WIDTH, 0.5)];
//    botomLineLabel.backgroundColor = UIColorHexRGBA(linBoardSepLineColor, 1.0);
//    [quiteBtn addSubview:botomLineLabel];
//
//    
//    
//    return quiteBtn;
//
//    
//}

-(void)quiteBtnAciton:(UIButton *)btn
{
    [[NSNotificationCenter defaultCenter] postNotificationName:@"logOff" object:nil];
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}


@end
